package com.rzgeo.rzmaplib.model;

import android.Manifest;
import android.app.Activity;
import android.os.Environment;

import java.io.File;

/**
 * Created by zhanghang on 2018/1/20.
 */

public class RmlEnv {


    public static final String[] Promssion = new String[]{
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.INTERNET,
            Manifest.permission.ACCESS_FINE_LOCATION,
    };
    private static final int SDK_PERMISSION_REQUEST = 127;

    private static RmlEnv _inst;
    private Activity _activity;
    private String _appName;
    private RmlAppMainDir _appDir;

    public static RmlEnv getInstance() {
        return _inst;
    }

    public static RmlEnv setup(String appName,Activity activity, OnInitialized onInitialized) {
        if (_inst == null) {
            _inst = new RmlEnv();
        }
        _inst._activity=activity;
        _inst._appName=appName;

        File appDir = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath()
                        + File.separator + appName);
        if((!appDir.exists())||
                (!appDir.isDirectory())){
            if(!appDir.mkdirs())
                onInitialized.Fail();
        }
        _inst._appDir=new RmlAppMainDir(activity,appDir);
        onInitialized.Pass();

        return _inst;
    }

    public RmlAppMainDir getAppDir() {
        return _appDir;
    }

    public Activity getActivity() {
        return _activity;
    }

    public String getAppName() {
        return _appName;
    }

    public interface OnInitialized {
        void Pass();

        void Fail();
    }
}
